#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1e5 + 5;
int n, m, prefix[N][10], ans[10], tmp[10];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("B.in", "r", stdin);
  freopen("B.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 0; i < 10; ++i) prefix[0][i] = i;
  for (int i = 1, l, r; i <= n; ++i) {
    scanf("%d%d", &l, &r);
    memcpy(prefix[i], prefix[i - 1], sizeof(prefix[i]));
    std::swap(prefix[i][l], prefix[i][r]);
  }
  for (int i = 1, x, y; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    for (int j = 0; j < 10; ++j) tmp[prefix[y][j]] = j;
    for (int j = 0; j < 10; ++j) { ans[tmp[prefix[x - 1][j]]] = j; }
    for (int j = 0; j < 10; ++j) printf("%d ", ans[j]);
    putchar('\n');
  }
  return 0;
}